﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace AliyunMobileTestTechnology.ViewModel.Commands
{
    public class ApplySettingsCommand:ICommand
    {
        private SettingsViewModel settings;

        public ApplySettingsCommand(SettingsViewModel settingsViewModel) 
        {
            settings = settingsViewModel;
            settings.OnPropertyUpdated += new SettingsViewModel.PropertyUpdatedEventHandler(settings_OnPropertyUpdated);
        }

        private void settings_OnPropertyUpdated()
        {
            CanExecuteChanged.Invoke(this, new EventArgs());
        }

        public bool CanExecute(object parameter)
        {
            return settings.HasPropertyChanged;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            settings.ApplyConfigurationChange();
        }
    }
}
